﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
    public abstract class DemoBase
    {
        public abstract string DemoName { get; }

        public void PrintText(string message, ConsoleColor consoleColor)
        {
            lock (this)
            {
                var oriColor = Console.ForegroundColor;
                Console.ForegroundColor = consoleColor;
                Console.WriteLine(message);
                Console.ForegroundColor = oriColor;
            }
        }

        public void Init()
        {
            PrintText($"------------{DemoName}------------", ConsoleColor.Cyan);
        }

        public void PrintInfo(string message)
        {
            Console.WriteLine(message);
        }

        public void PrintError(string message)
        {
            PrintText(message, ConsoleColor.Red);
        }

        public void PrintSuccess(string message)
        {
            PrintText(message, ConsoleColor.Green);
        }

        public void PrintTimeNow()
        {
            Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
        }

        public void PrintLog(string message, ConsoleColor consoleColor = ConsoleColor.DarkGray)
        {
            PrintText($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}\t{message}", consoleColor);
        }

        public void PrintSuccessLog(string message)
        {
            PrintLog(message, ConsoleColor.DarkGreen);
        }

        public void PrintErrorLog(string message)
        {
            PrintLog(message, ConsoleColor.DarkRed);
        }

        public abstract void RunDemo();
    }
}
